package br.com.eduquiz.session;

import br.com.eduquiz.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("questaoHome")
public class QuestaoHome extends EntityHome<Questao> {
	
	private static final long serialVersionUID = 4634798387430824905L;
	
	@In(create = true)
	private QuestionarioHome questionarioHome;

	public void setQuestaoId(Long id) {
		setId(id);
	}

	public Long getQuestaoId() {
		return (Long) getId();
	}

	@Override
	protected Questao createInstance() {
		Questao questao = new Questao();
		return questao;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Questionario questionario = questionarioHome.getDefinedInstance();
		if (questionario != null) {
			getInstance().setQuestionario(questionario);
		}
	}

	public boolean isWired() {
		return true;
	}

	public Questao getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Resposta> getResposta() {
		return getInstance().getResposta() == null ? null : new ArrayList<Resposta>(
				getInstance().getResposta());
	}

}
